'use strict';
let nunjucks=require('nunjucks');
function createEnv(path,opts){
    path=path||'views';
    opts=opts||{};
    let ConOpts={
        autoescape:opts.autoescape===undefined?true:opts.autoescape,
        throwOnUndefined:opts.throwOnUndefined===undefined?false:opts.throwOnUndefined,
        lstripBlock:opts.lstripBlock===undefined?true:opts.lstripBlock,
        trimBlock:opts.trimBlock===undefined?false:opts.trimBlock,
        watch:opts.watch===undefined?true:opts.watch,
        noCache:opts.noCache===undefined?false:opts.noCache
    }
    let env=nunjucks.configure(path,ConOpts);
    return env;
}
module.exports=async(context,next)=>{
    context.render=(view,model)=>{
        let env=createEnv();
        context.body=env.render(view,model);
    }
    await next();
}